package com.personal.website.lottery.table

import java.util

import scala.collection.JavaConverters._


/**
 * Created by Gavin on 2015/12/13.
 */
class MainTable(issue: Int,redBalls: Seq[Int], blueBall: Int) extends Table(issue,redBalls,blueBall){

  override def createRecord() = MainTable.ALL_EXISTS_BALLS.map(x => if(redBalls.contains(x)) x else DEFAULT_NON_EXISTS_VALUE)

  def createOddVsEven() = {
    val odds = redBalls.map(_ % 2).sum
    s"${odds}:${redBalls.size - odds}"
  }

  override def toString() = Seq(Seq(issue), Seq(createOddVsEven()), Seq(createSum()), createRecord()).flatten.mkString(";")
}

object MainTable{
  def apply(issue: Int,redBalls: Seq[Int], blueBall: Int) = new MainTable(issue,redBalls,blueBall)
  def apply(issue: Int,allBalls: Seq[Int]) = new MainTable(issue,allBalls.init,allBalls.last)
  def newInstance(issue: Integer,redBalls: util.List[Integer],blueBall: Integer) = new MainTable(issue.toInt, redBalls.asScala.map(_.toInt),blueBall.toInt)

  val ALL_EXISTS_BALLS = (1 to 33)

  def headString = Seq("issue","odd:even","sum",ALL_EXISTS_BALLS).mkString("|")
}
